package com.thermofisher.dsc.amanda.common.excel.model;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.BaseRowModel;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;

/**
 * @author wenjie.yang on 4/3/2019.
 */
@Getter
@Table(name = "Inventory_cache")
public class InventoryExcel extends BaseRowModel  implements Validate{
  public static final  DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  @ExcelProperty(index = 1)
  @Column(name = "sku_nbr")
  private String  skuNo;

  @ExcelProperty(index = 4)
  @Column(name = "storage_loc")
  private String storageLoc;

  @ExcelProperty(index = 6)
  @Column(name = "lot")
  private String lot;

  @ExcelProperty(index = 11)
  @Column(name = "quantity")
  private String quantity;

  @ExcelProperty(index = 8)
  @Column(name = "total_on_hand")
  private String totalOnHand;

  @ExcelProperty(index = 12)
  @Column(name = "lot_expiration_date")
  private String lotExpirationDate;


  public void setSkuNo(String skuNo) {
    this.skuNo = skuNo== null?skuNo:skuNo.trim();
  }

  public void setStorageLoc(String storageLoc) {
    this.storageLoc = storageLoc== null?storageLoc:storageLoc.trim();
  }

  public void setLot(String lot) {
    this.lot = lot== null?lot:lot.trim();
  }

  public void setQuantity(String quantity) {
    this.quantity = quantity== null?quantity:quantity.trim();
  }

  public void setTotalOnHand(String totalOnHand) {
    this.totalOnHand = totalOnHand== null?totalOnHand:totalOnHand.trim();
  }

  public void setLotExpirationDate(String lotExpirationDate) {
    try {
      sdf.parse(lotExpirationDate);
    } catch (Exception e) {
      this.lotExpirationDate = null;
      return;
    }
    this.lotExpirationDate = lotExpirationDate== null?lotExpirationDate:lotExpirationDate.trim();
  }


  @Override
  public String toString() {
    return "IventoryExcel{" +
        "skuNo='" + skuNo + '\'' +
        ", storageLoc='" + storageLoc + '\'' +
        ", lot='" + lot + '\'' +
        ", quantity='" + quantity + '\'' +
        ", totalOnHand='" + totalOnHand + '\'' +
        ", lotExpirationDate='" + lotExpirationDate + '\'' +
        '}';
  }

  @Override
  public boolean validate() {
    if(StringUtils.isBlank(storageLoc)){
      return false;
    }
    return true;
  }
}
